<?php
class ArticleApp extends BackendApp
{
    function __construct()
    {
        $this->ArticleApp();
    }
    function ArticleApp()
    {
        $this->_article_mod = &m('article');
		parent::__construct();
    }

	/*============================公司网站的关于我们的页面调用==============================*/
    function abouts()
	{
        $now_code = empty($_GET['code']) ? 0 : htmldecode($_GET['code']);
        if (!$now_code)
        {	
			$this->show_warning('对不起，访问过程中遇到了问题');
			return;			
		}

        //缓存数据调用
		$cache_server =& cache_server();		
		$key = 'abouts_get_list';
        $category_about = $cache_server->get($key);
        if ($category_about === false)
        {
			//调出所有公司内容列表
			$abouts_mod = &m('abouts');
			$category_about = $abouts_mod->find(array( 'order' => 'sort_order, cate_id' ));
			$cache_server->set($key, $category_about, 86400);
		}		

		foreach ($category_about as $key => $for_about)
		{
			if ($now_code == $for_about['code']){
				$now_about= array('title' => $for_about['cate_name'], 'content'=> $for_about['content'],'content_wap'=> $for_about['content_wap'], 'code'=> $for_about['code'], 'parent_id'=> $for_about['parent_id']);
				$location[1]= array('text' => $for_about['cate_name'], 'url'=> url('app=article&act=abouts&code=' . $for_about['code']), 'cate_id'=> $for_about['cate_id'], 'code'=> $for_about['code']);
			}
		}
		$category = array();
		foreach ($category_about as $key => $for_about)
		{
			if ($for_about['parent_id']>0)
			{
				$category[$for_about['parent_id']]['list'][] = $for_about;
			}else{
				$category[$key] = $for_about;
			}
			if ($now_about['parent_id'] == $for_about['cate_id']){
				$location[0]= array('text' => $for_about['cate_name'], 'url'=> url('app=article&act=abouts&code=' . $for_about['code']), 'cate_id'=> $for_about['cate_id'], 'code'=> $for_about['code']);
			}			
		}
		if(!$now_about){
            $this->show_warning('没有找到相关内容！');
            return;
		}
        /* 当前位置 */
		if(count($location)>1)//数组排序
		{ 
		   ksort($location);
	    }else{
		  $location && $location=array_values($location);
	    }
		$this->assign('location', $location);		

		$this->assign('now_about', $now_about);
		$this->assign('category_about', $category);
		$this->assign('curitem', $now_about['title']);
		$this->_config_seo(array( 'title' => $now_about['title'] . ' - ' . Conf::get('site_name') ));	
		$this->import_resource(array( 'style' =>  'res:style/css_wap.css?v=1' ));	
		$this->display('about.content.html');
	}
    function abouts_view()
    {
        $article_id = empty($_GET['article_id']) ? 0 : intval($_GET['article_id']);
        if ($article_id>0)
        {
            $article = $this->_article_mod->get('article_id=' . $article_id . ' AND code = "" AND if_show=1 AND store_id=0');
            if (!$article)
            {
                $this->show_warning('no_such_article');
                return;
            }
            if ($article['link']){ //外链文章跳转
                header("HTTP/1.1 301 Moved Permanently");
                header('location:'.$article['link']);
                return;
            }
        }

		//默认性显示文章
		if(!$article['article_id'] && !$article['title']){
			$article['article_id']=$ganggao["articles"][0]['article_id'];
			$article['title']=$ganggao["articles"][0]['title'];
			$article['content']=$ganggao["articles"][0]['content'];
		}
		$this->assign('article', $article);
				
        $this->_config_seo(array(
            'title'       => $article['title'] . ' - 新闻公告 - ' . Conf::get('site_name'),
            'keywords'    => $article['title'] . ',新闻公告,' . Conf::get('site_name'),
            'description' => $article['title'] . ',新闻公告,' . Conf::get('site_name')
        ));

		$this->assign('curitem', "新闻公告详情");
		$this->import_resource(array( 'style' =>  'res:style/css_wap.css' ));
		$this->display('about.news.html');
    }
	//新闻列表
	function news_list()
	{
		//调出新闻公告
		$cate_ids = 2;
		$page = $this->_get_page(12);   //获取分页信息
		$conditions = " AND cate_id = '{$cate_ids}'";
		$news_list = $this->_article_mod->find(array(
			'fields'        => 'this.title,this.add_time',
			'conditions'  => 'if_show=1 AND store_id=0' . $conditions,
			'limit'   => $page['limit'],
			'order'   => $sort_order,
			'count'   => true   //允许统计
		)); 
		$page['item_count'] = $this->_article_mod->getCount();	
		$this->_format_page($page);
		$this->assign('page_info', $page);
		$this->assign('news_list', $news_list);

		$this->assign('curitem', "新闻公告");
		$this->import_resource(array( 'style' =>  'res:style/css_wap.css' ));
		$this->_config_seo(array( 'title' => '新闻公告 - ' . Conf::get('site_name') ));
		$this->display('about.newlist.html');		
	}
    
	function _get_article($type='')
    {
        $conditions = '';
        $per = '';
        switch ($type)
        {
            case 'new' : $sort_order = 'add_time DESC,sort_order ASC';
            $per=10;
            break;
            case 'all' : $sort_order = 'sort_order ASC,add_time DESC';
            $per=25;
            break;
        }
        $page = $this->_get_page($per);   //获取分页信息
        !empty($this->_cate_ids)&& $conditions = ' AND cate_id ' . db_create_in($this->_cate_ids);		
        $articles = $this->_article_mod->find(array(
            'conditions'  => 'if_show=1 AND store_id=0 AND code = ""' . $conditions,
            'limit'   => $page['limit'],
            'order'   => $sort_order,
            'count'   => true   //允许统计
        )); //找出所有符合条件的文章
        $page['item_count'] = $this->_article_mod->getCount();
        foreach ($articles as $key => $article)
        {
            $articles[$key]['target'] = $article[link] ? '_blank' : '_self';
        }		
        return array('page'=>$page, 'articles'=>$articles);
    }
}
?>